<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>人员脚本导入</title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<form class="layui-form" style="height: 494px;overflow: auto;" lay-filter="identityForm">
    <div class="layui-btn-container" style="position: absolute;bottom:0;width: 100%;text-align: center">
        <button class="layui-btn" lay-submit lay-filter="identityForm">保存
        </button>
        <button class="layui-btn layui-btn-danger" id="returnIdentityList">取消</button>
    </div>
    <table class="layui-table">
        <tr>
            <td style="width: 70px">名称<span style="color:red">*</span></td>
            <td>
                <div class="layui-input-inline">
                    <input type="hidden" name="id"  autocomplete="off" class="layui-input" >
                    <input type="text" name="identityName" id="identityName" lay-verify="required" autocomplete="off"
                           placeholder="请输入标题" class="layui-input" maxlength="25" >
                </div>
            </td>
        </tr>
        <tr>
            <td>别名<span style="color:red">*</span></td>
            <td>
                <div class="layui-input-inline">
                    <input type="text" id="alias" name="alias" lay-verify="required" placeholder="请输入别名" autocomplete="off"
                           class="layui-input" maxlength="10" >
                </div>
            </td>
        </tr>
        <tr>
            <td>规则<span style="color:red">*</span></td>
            <td>
                <div class="layui-input-inline">
                    <input type="text" lay-verify="required" placeholder="请输入" name="rule" id="rule" autocomplete="off" class="layui-input"
                           value="{yyyy}{MM}{dd}{NO}">
                    <p>{yyyy}{MM}{dd}{NO}</p>
                    <p>{yyyy}表示年份</p>
                    <p>{MM}表示月份，如果月份小于10，则加零补齐，如1月份表示为01。</p>
                    <p>{mm}表示月份，月份不补齐，如1月份表示为1。</p>
                    <p>{DD}表示日，如果小于10号，则加零补齐，如1号表示为01。</p>
                    <p>{dd}表示日，日期不补齐，如1号表示为1。</p>
                    <p>{NO}表示流水号，前面补零。</p>
                    <p>{no}表示流水号，后面补零。</p>
                    <p>{ORG}表示当前用户所属组织的code代码</p>
                    <p>{UC}表示当前用户所提交的code代码</p>
                </div>
            </td>
        </tr>
        <tr>
            <td>生成类型</td>
            <td>
                <div class="layui-input-inline">
                    <input type="radio" name="genType" lay-filter="genType" value="1" title="每天生成"  >
                    <input type="radio" name="genType" lay-filter="genType" value="2" title="每月生成"  >
                    <input type="radio" name="genType" lay-filter="genType" value="3" title="每年生成"  >
                    <input type="radio" name="genType" lay-filter="genType" value="0" title="递增"     >
                    <p>流水号生成规则：</p>
                    <p>1.每天生成。每天从初始值开始计数。</p>
                    <p>2.递增，流水号一直增加。</p>
                </div>
            </td>
        </tr>
        <tr>
            <td>流水号长度<span style="color:red">*</span></td>
            <td>
                <div class="layui-input-inline">
                    <input type="text" lay-verify="required|number" placeholder="请输入" autocomplete="off"  name="noLength" id="noLength" class="layui-input"
                           value="5">
                    <p>这个长度表示当前流水号的长度数，只包括流水号部分{NO},如果长度为5，当前流水号为5，则在流水号前补4个0，表示为00005。</p>
                    <p>{no}如果长度为5，当前流水号为501，则在流水号后面补5个0，表示为50100000，如果长度为1，则流水号一直递增。</p>
                </div>
            </td>
        </tr>
        <tr>
            <td>初始值<span style="color:red">*</span></td>
            <td>
                <div class="layui-input-inline">
                    <input type="text" lay-verify="required|number" placeholder="请输入" autocomplete="off" name="initValue" id="initValue" class="layui-input"
                           value="1">
                </div>
            </td>
        </tr>
        <tr>
            <td>步长<span style="color:red">*</span></td>
            <td>
                <div class="layui-input-inline">
                    <input type="text" lay-verify="required|number" placeholder="请输入" autocomplete="off" name="step" id="step" class="layui-input"
                           value="1">
                    <p>流水号每次递加的数字，默认步长为1。比如步长为2，则每次获取流水号则在原来的基础上加2。</p>
                </div>
            </td>
        </tr>
        <tr>
            <td>用户编号</td>
            <td>
                <div class="layui-input-inline">
                    <input type="text" placeholder="请输入" autocomplete="off" name="userCode"
                           id="userCode" class="layui-input" >
                    <p>流水号添加用户编码，默认为空，如果需要添加用户编码还需要在规则中添加相对应的规则代码。</p>
                </div>
            </td>
        </tr>
    </table>
</form>

<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','form', 'jquery', 'table', 'layer','commons'], function () {
        var form = layui.form
            , layer = layui.layer;
        var table = layui.table;
        var setter = layui.setter;
        var commons = layui.commons;
        var $ = layui.$;
        form.render();
        form.val("identityForm", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
            "id": "${identity.id}"
            ,"identityName": "${identity.identityName}"
            ,"alias": "${identity.alias}"
            ,"rule": "${identity.rule}"
            ,"genType": "${identity.genType}"
            ,"noLength": "${identity.noLength}".replace(/,/g,'')
            ,"initValue": "${identity.initValue}".replace(/,/g,'')
            ,"step": "${identity.step}".replace(/,/g,'')
            ,"userCode": "${identity.userCode}"
        });
        //自动生成别名
        $("#identityName").change(function () {
            var str = $(this).val();
            if (str == "") return;
            var arrRslt = component.chineseToPinyinAlias(str);
            $("#alias").val(arrRslt[0]);
        });


        $("#returnIdentityList").click(function(){
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        });

        //监听提交
        form.on('submit(identityForm)', function (data) {
            $.ajax({
                url: serverPath.workflowPath + setter.workflowLinkPath +"identity/add",
                type: "POST",
                contentType: 'application/json',
                dataType: 'json',
                data: JSON.stringify(data.field),
                success: function (result) {
                    if (commons._filterRecord(result)) {
                        layer.alert(result.msg, function (index) {
                            layer.close(index);
                            parent.layui.table.reload('serNumber', {
                                page: {curr: 1}
                            });
                            parent.layui.totalFilter.init('serNumber');
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });
                    } else {
                        layer.alert(result.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("保存失败！" + XMLHttpRequest.status);
                }
            });
            return false;
        });
    });
</script>
</body>
</html>